package com.yglab.sqpoll.webapp.controller;

import java.util.List;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yglab.sqpoll.model.Survey;
import com.yglab.sqpoll.service.SurveyService;

/**
 * Handles requests for the poll application page.
 */
@Controller
public class PollController {

	private static final Logger logger = LoggerFactory.getLogger(PollController.class);

	@Autowired
	private SurveyService surveyService;
	
	/**
	 * Gets the my poll list to render by returning its name.
	 */
	@RequestMapping(value = "/myPollList", method = RequestMethod.GET)
	public String getMyPollList(Locale locale, Model model) {
		logger.info("the client locale = " + locale.toString());
		
		Survey params = new Survey();
		params.setCreateUserId("louie");
		List<Survey> myPolls = surveyService.getSurveys(params);

		model.addAttribute("myCreatePolls", myPolls);

		return "myPollList";
	}

}
